using Imaginarium.team;
using System;
using GameEngine.utils.console;
using System.Collections.Generic;
namespace Imaginarium.battleSistem
{
    public class BattleCommand: IComparable
    {
        #region Attributes
        public BattleOption.BattleOptionEnum type { get; set; }
        public Character Performer { get; set; }
        public Character Target { get; set; }
        public bool executed { get; set; }
        public List<DamageMaker> damagesDealt {get; set;}
        #endregion
        #region Constructors

        public BattleCommand(Character performer, Character target)
        {
            this.Performer = performer;
            this.Target = target;
            executed = false;
            damagesDealt = new List<DamageMaker>();
        }
        public BattleCommand(Character performer):
            this(performer, null)
        { }

        public override string ToString()
        {
            string ans = "";
            ans += "Performer: " + Performer.name + " - ";
            ans += (Target!=null)?("Target: " + Target.name +"\n") : "";
            return ans;
        }

        #endregion
        #region Functionality
        public virtual void startAnimation() 
        { }
        public virtual void execute() {
            executed = true;
            ImaginariumConsole.getInstance().write("Execute BattleCommand: ");
            ImaginariumConsole.getInstance().write(this);
        }
        protected DamageMaker getMiss() 
        {
            DamageMaker bd = new DamageMaker();
            bd.Target = Target;
            bd.missed = true;
            return bd;
        }
        #endregion


        #region IComparable Members
        //Sortable by agility
        public int CompareTo(object obj)
        {
            BattleCommand other = (BattleCommand)obj; //objects compared should always be of the same type
            if (this.type == BattleOption.BattleOptionEnum.Defend && other.type != BattleOption.BattleOptionEnum.Defend)
                return 1;
            if (this.type != BattleOption.BattleOptionEnum.Defend && other.type == BattleOption.BattleOptionEnum.Defend)
                return -1;

            int thisAgi = this.Performer.getFinalStats().agility, otherAgi = other.Performer.getFinalStats().agility;
            return thisAgi - otherAgi;
        }

        #endregion
    }
}